<?php 
class Article_model extends CI_Model {
	public $table_name="article";
	public function count_all(){
		return $this->db->count_all_results($this->table_name);
	}
    public	function get_all(){
		$query=$this->db->get('article');
	   return $query->result();

	}
	public function get_by_page($page,$page_size){
       $offset = ($page-1)*$page_size;
       $query = $this->db->order_by('id','DESC')->limit($page_size,$offset)->get($this->table_name);
       return $query->result();
	}
	public	function get_one($id){
		$query=$this->db->where("id",$id)->get('article');
	   return $query->row();

	}
	public	function get_by_catalog_id($cata_id){
		$query=$this->db->where("catalog_id",$cata_id)->get('article');
	   return $query->result();

	}
	public function view_once($id){
		$this->db->query("update $this->table_name set `view`=`view`+1 where id=$id");

	}
	public function add_one($data){
		$data['create_time']=time();
		$this->db->insert($this->table_name, $data);
		
		
}
  public function edit_one($id,$data){
		$this->db->where('id', $id);
       $this->db->update($this->table_name, $data);
		
		
 }

   public function delete($id){
   	$this->db->delete($this->table_name, array('id' => $id));
   }

   
   public function recommend($id){
   	   $result=$this->get_one($id);
       $data=array(
        'recommend'=>$result->recommend==1?0:1,
     	);

       $this->db->where('id', $id);
       $this->db->update($this->table_name, $data);
		

} 
}

?>



